import java.util.Arrays;
import java.util.Scanner;

public class Test2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int []arr = new int[45];
        arr[0] = 1;
        arr[1] = 1;
        for (int i = 2; i < 45; i++) {
            arr[i] = arr[i - 1] + arr[i - 2];
        }
        while(in.hasNext()){
            int n = in.nextInt();
            int result = Arrays.binarySearch(arr, n);
            if(result >= 0){
                System.out.println(0);
            }else {
                System.out.println(Math.min((arr[Math.abs(result) - 1] - n),(n - arr[Math.abs(result) - 2])));
            }
        }

    }
}